# ---------------------------------------------------------------
# Copyright (c) 2023-2024 ETH Zurich, Lukas Hoyer. All rights reserved.
# Licensed under the Apache License, Version 2.0
# ---------------------------------------------------------------

# dataset settings
img_norm_cfg = dict(
    mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
#crop_size = (1024, 1024)
crop_size = (512,512)

potsdam_train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations'),
    #dict(type='Resize', img_scale=(512,512)),
    dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
    dict(type='RandomFlip', prob=0.5),
    # dict(type='PhotoMetricDistortion'),  # is applied later in DACS.py
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img','gt_semantic_seg']),
]

potsdam_ref_train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='Resize', img_scale=(512, 512)),  # original 1920x1080
    dict(type='RandomCrop', crop_size=crop_size),
    dict(type='RandomFlip', prob=0.5),
    # dict(type='PhotoMetricDistortion'),  # is applied later in DACS.py
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img']),
]
train_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(type='LoadAnnotations', reduce_zero_label=True),
    dict(type='Resize', img_scale=(512, 512), ratio_range=(0.5, 2.0)),
    dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
    dict(type='RandomFlip', prob=0.5),
    # dict(type='PhotoMetricDistortion'),  # is applied later in dacs.py
    dict(type='Normalize', **img_norm_cfg),
    dict(type='Pad', size=crop_size, pad_val=0, seg_pad_val=255),
    dict(type='DefaultFormatBundle'),
    dict(type='Collect', keys=['img']),
]
test_pipeline = [
    dict(type='LoadImageFromFile'),
    dict(
        type='MultiScaleFlipAug',
        img_scale=(512, 512),
        # img_ratios=[0.5, 0.75, 1.0, 1.25, 1.5, 1.75],
        flip=False,
        transforms=[
            dict(type='Resize', keep_ratio=True),
            dict(type='RandomFlip'),
            dict(type='Normalize', **img_norm_cfg),
            dict(type='ImageToTensor', keys=['img']),
            dict(type='Collect', keys=['img']),
        ])
]
data = dict(
    # samples_per_gpu = 1,
    samples_per_gpu = 2,  # 确保这个值是偶数
    workers_per_gpu = 2,
    train=dict(
        type='UDAMediumDataset',
        source=dict(
            type='PotsdamDataset',
            data_root = 'data/vaihingen',
            img_dir = 'img_dir/train',
            ann_dir = 'ann_dir/train',
            pipeline=potsdam_train_pipeline),
        intermediate = dict(
            type='ACDCRefDataset',
            # data_root='/mnt/HRDA-master/data/vaihingen_imd_10',
            data_root='data/potsdam_imd_10',
            img_dir='img_dir/train',
            ann_dir='ann_dir/train',
            pipeline=potsdam_ref_train_pipeline),
        target=dict(
            type='ISPRSDataset',
            data_root='data/potsdam1',
            img_dir='img_dir',
            ann_dir='ann_dir',
            pipeline=train_pipeline)),
    val=dict(
        type='ISPRSDataset',
        data_root='data/potsdam',
        img_dir='img_dir/val',
        ann_dir='ann_dir/val',
        pipeline=test_pipeline),
    test=dict(
        type='ISPRSDataset',
        data_root='data/potsdam',
        img_dir='img_dir/val',
        ann_dir='ann_dir/val',
        pipeline=test_pipeline)
    )
